/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
	package combi.graph;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.jgrapht.GraphPath;

public class Kpaths<V,E> extends ArrayList<GraphPath<V, E>>{

	private int k;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Kpaths()
	{
		super();
		k = 0;
	}
	
	/**
	 * 
	 * @param k : number of path
	 */
	public Kpaths(int k)
	{
		super(k);
		this.k = k;
	}

	public Kpaths(Collection<GraphPath<V, E>> paths)
	{
		super(paths);
		this.k = this.size();
	}
	
	public boolean add(GraphPath<V, E> p)
	{
		k++;
		return super.add(p);
	}
	

	public boolean remove(GraphPath<V, E> p)
	{
		k--;
		return super.remove(p);
	}
	
	public int getK()
	{
		return k;
	}
	
	public List<List<V>> toVerticesList()
	{
		List<List<V>> result = new ArrayList<List<V>>(this.size());
		for (int i = 0; i < this.size(); i++)
		{
			result.add(this.toVerticesList(this.get(i)));
		}
		return result;
	}
	
	public List<V> toVerticesList(GraphPath<V, E> p)
	{
		List<E> edgesList = p.getEdgeList();
		List<V>	result =  new ArrayList<V>(edgesList.size()+1);
		result.add(p.getGraph().getEdgeSource(edgesList.get(0)));
		for (E e : edgesList)
		{
			result.add(p.getGraph().getEdgeTarget(e));
		}
		return result;
	}
	
	public String toString() 
	{
		String result = "";
		for (GraphPath<V, E> p : this)
		{
			result += p.getWeight() + " :" + toVerticesList(p).toString() + "\n";
		}
		return result;
	}
}
